<template>
  <demoBlock title="可选择" padding>
    <vcu-table :row-selection="rowSelection" :columns="columns" :datas="data" bordered>
      
    </vcu-table>
  </demoBlock>
</template>

<script>
import { defineComponent, ref } from "vue";
const columns = [
  {
    title: "姓名",
    dataIndex: "name",
    key: "name",
  },
  {
    title: "年龄",
    dataIndex: "age",
    key: "age",
    defaultSortOrder: 'descend',
    sorter: (a, b) => a.age - b.age,
  },
  {
    title: "地址",
    dataIndex: "address",
    key: "address",
  },
  {
    title: "标签",
    key: "tags",
    dataIndex: "tags",
  },
];

const data = [
  {
    key: "1",
    name: "张三",
    age: 32,
    address: "火星",
    tags: "漂亮的",
  },
  {
    key: "2",
    name: "李四",
    age: 42,
    address: "地球",
    tags: "失败者",
  },
  {
    key: "3",
    name: "王五",
    age: 32,
    address: "月亮",
    tags: "冰冷的",
  },
];
export default defineComponent({
  setup() {
    const rowSelection = {
      trigger: "row",
      onChange: (selectedRowKeys, selectedRows) => {
        console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
      },
      getCheckboxProps: (record) => ({
        disabled: record.name === 'Disabled User', // Column configuration not to be checked
        name: record.name,
      }),
    };
    return {
      data,
      columns,
      rowSelection,
    };
  },
});
</script>
